package com.my.hzb.user.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.framelib.utils.Page;
import com.my.hzb.entiy.Address;
import com.my.hzb.entiy.UserMessage;
import com.my.hzb.mapper.UserMessageMapper;
import com.my.hzb.entiy.UserMessageExample;
import com.my.hzb.entiy.UserMessageExample.Criteria;

public class UserMessageServiceImpl implements UserMessageService {

	@Autowired
	private UserMessageMapper userMessageMapper;
	
	@Override
	public void add(UserMessage userMessage) {
		userMessageMapper.insert(userMessage);
	}

	@Override
	public void update(UserMessage userMessage) {
		userMessageMapper.updateByPrimaryKey(userMessage);
	}
	@Override
	public void delete(UserMessage userMessage) {
	}

	@Override
	public UserMessage getOne(Integer id) {
		return userMessageMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<UserMessage> find(UserMessage userMessage,Page page) {
		UserMessageExample example = new UserMessageExample();
		if(null!=page){
			example.setPage(page);
		}
		if(null==userMessage){
			return userMessageMapper.selectByExample(example);
		}
		Criteria cre = example.createCriteria();
		if(null!=userMessage.getUserName()){
			cre.andUserNameEqualTo(userMessage.getUserName());
		}
		return userMessageMapper.selectByExample(example);
	}

	@Override
	public List<UserMessage> getDefByUser(String userName) {
		UserMessageExample example = new UserMessageExample();
		Criteria cre = example.createCriteria();
		cre.andUserNameEqualTo(userName);
		return userMessageMapper.selectByExample(example);
	}

	@Override
	public int count(UserMessage userMessage) {
		UserMessageExample example = new UserMessageExample();
		Criteria cre = example.createCriteria();
		if(null!=userMessage.getUserName()){
			cre.andUserNameEqualTo(userMessage.getUserName());
		}
		return userMessageMapper.countByExample(example);
	}

}
